def isPrime(x):
    if x == 1:return False
    chislo = True
    k = x - 1
    while k > 1:
        if not x % k:
            chislo = False
            break
        k-= 1
    return chislo
n = input()
if 999 < int(n) < 10000:
    r = []
    for i in range(len(n)):
        for k in range(i + 1, len(n) + 1):
            x = int(n[i:k])
            if isPrime(x):
                r += [x]
    print(max(r) if r else 0)
else:
    print('0')
